<template>
  <div class="app-container">
    <SearchForm
      v-show="showSearch"
      v-model="queryParams"
      :options="options.formOps"
      @onQuery="getList"
    >
      <template #operationTime="{ filterForm }">
        <el-form-item label="投用时间">
          <el-date-picker
            v-model="filterForm.time"
            type="daterange"
            range-separator="-"
            style="width: 100%"
            @change="operationTimeChange"
            format="MM-DD"
            value-format="YYYY-MM-DD"
          />
        </el-form-item>
      </template>
    </SearchForm>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="Plus"
          @click="handleAdd"
          v-hasPermi="['inspect:call:polic:equipment:add']"
          >新增</el-button
        >
      </el-col>

      <el-col :span="1.5">
        <ImportExcel
          type="primary"
          :url="APIS.url"
          plain
          icon="Plus"
          @success="getList"
          v-hasPermi="['inspect:call:polic:equipment:importData']"
        ></ImportExcel>
      </el-col>
      <el-col :span="1.5">
        <ExportExcel
          type="primary"
          :url="APIS.url"
          plain
          v-hasPermi="['inspect:call:polic:equipment:importTemplate']"
        ></ExportExcel>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="Download"
          @click="handleExport"
          v-hasPermi="['inspect:call:polic:equipment:export']"
          >导出</el-button
        >
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="Delete"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:user:remove']"
          >删除</el-button
        >
      </el-col> -->

      <!-- <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="Download"
          @click="handleExport"
          v-hasPermi="['system:user:export']"
          >导出</el-button
        >
      </el-col> -->
      <right-toolbar
        v-model:showSearch="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>
    <Table
      ref="table"
      :auto-featch="true"
      :fetch-data="fetchData"
      :options="options.table"
    >
      <template #actionButton="{ row }">
        <el-button
          type="text"
          icon="Edit"
          @click="handleEdit(row)"
          v-hasPermi="['inspect:call:polic:equipment:edit']"
          >修改</el-button
        >

        <el-button
          type="text"
          icon="Delete"
          style="color: red"
          @click="handleDel(row)"
          v-hasPermi="['inspect:call:polic:equipment:delete']"
          >删除</el-button
        >
      </template></Table
    >
    <DialogVform
      :formJson="formJson"
      ref="dialogVform"
      @onSubmit="onSubmit"
    ></DialogVform>
  </div>
</template>

<script setup>
import Table from "@/components/Table/index.vue";
import SearchForm from "@/components/searchForm/index";
import DialogVform from "@/components/dialogVform/index";
import { apis as APIS } from "@/api/aqsc/scss/jcbjss.js";
import formJson from "./components/options.json";
import { useAsyncData, useFormJson } from "@/views/hooks/useAsyncData.js";
import ImportExcel from "@/components/ImportExcel/index.vue";
import ExportExcel from "@/components/ExportExcel/index.vue";
const { proxy } = getCurrentInstance();
const operationTimeChange = (data) => {
  if (data && data.length) {
    queryParams.value.operationTimeStart = data[0];
    queryParams.value.operationTimeEnd = data[1];
  } else {
    queryParams.value.operationTimeStart = null;
    queryParams.value.operationTimeEnd = null;
  }
};
const ops = useFormJson(formJson, {
  sort: [],
  sortable: [],
});
const options = reactive({
  table: ops,
  formOps: ops.filter((i) =>
    [
      "cycle",
      "confirmMode",
      "operationTime",
      "equipmentName",
      "gaugesClass",
    ].includes(i.prop)
  ),
});
const showSearch = ref(true);

const dialogVform = ref();

const table = ref();

const {
  onSubmit,
  fetchData,
  handleAdd,
  handleEdit,
  getList,
  handleDel,
  queryParams,
  handleExport,
} = useAsyncData({ APIS, formJson, dialogVform, table, proxy });
</script>

<style lang="scss" scoped></style>
